/**
 * 
 */
package net.webownia.api.commons;

import java.util.ArrayList;
import java.util.List;

/**
 * @author abarczewski
 * 
 */
public final class NumberUtil {
	
	private NumberUtil() {
	}
	
	/**
	 * Sprawdzenie czy numer jest w zakresie
	 * 
	 * @param printNumber
	 * @param printNumberStart
	 * @param printNumberEnd
	 * @return
	 */
	public static boolean isBetween(String printNumber, String printNumberStart, String printNumberEnd) {
		return (printNumber.length() == printNumberStart.length() && (Long.valueOf(printNumber) >= Long
				.valueOf(printNumberStart) && Long.valueOf(printNumber) <= Long.valueOf(printNumberEnd)));
	}

	/**
	 * <pre>
	 * Metoda zwraca kolekcj� numer�w w pe�nej postaci, np: '00002' poprzedzonymi zerami
	 * 
	 * @param startNumber
	 *            pocz�tkowy numer druku poprzedzony zerami
	 * @param endNumber
	 *            ko�cowy numer druku poprzedzony zerami
	 * @return
	 * @throws Exception 
	 */
	public static List<String> generatePrintNumbers(String startNumber, String endNumber) throws Exception  {
		if(startNumber.length() != endNumber.length()) {
			throw new Exception();
		}
		List<String> printNumberList = new ArrayList<String>();
		for(long number = Long.valueOf(startNumber); number <= Long.valueOf(endNumber); number++) {
			printNumberList.add(longNumberToStringNumber(startNumber.length(), number, "0"));
		}
		return printNumberList;
	}

	/**
	 * Zamiana numeru druku na druk w postaci znakowej poprzedzonego prefixem
	 * 
	 * @param length
	 *            d�ugo�� numeru
	 * @param number
	 *            numer druku bez prefixu
	 * @param prefix
	 *            
	 * @return
	 */
	public static String longNumberToStringNumber(int length, long number, String prefix) {
		String numberString = String.valueOf(number);
		int lengthNumber = numberString.length();
		int quantityZeros = length - lengthNumber;
		String zerosPrefix = "";
		if(quantityZeros > 0) {
			for(int i = 1; i <= quantityZeros; i++) {
				zerosPrefix = zerosPrefix.concat(prefix);
			}
		}
		return zerosPrefix.concat(numberString);
	}
}
